/**
 * 
 */
$(document).ready(function() {
	
	$('.info').click(function(){
		var id = $(this).attr("id");
		window.location.href="initInfo?id="+id;
		
		//window.parent.document.getElementById("rightIframe").src = "info.jsp?id="+$(this).attr("id");
		//parent.location.href="index.jsp?a=info.jsp"
	});
	//点击购买
	$('.addCar').click(function(){		
		var uid = window.parent.document.getElementsByClassName("handler")[0].id;
		if(uid == "" || uid == null){
			alert("请先登录账号");
			return ;
		}
		var cid = $(this).attr("id");
		$.ajax({
			type:"get",
			url :"car/addCar?uid="+uid+"&cid="+cid,
			dateType:"json",
			success:function(){
				window.location.href="car?id="+uid;
			},
			error:function(){
				window.location.href="car?id="+uid;
			}
		});
	});
	
	

	$(function(){  	
		//获取地址栏信息
		var str = window.location.search;
		var strs = str.split("&");
		typeId = strs[0].split("=")[1];
		keyWord = decodeURI(strs[1].split("=")[1]);//获取关键字并解码
		//点击下一页
		$("#nextPage").click(function(){ 
			if(keyWord == "" || keyWord==null){
				keyWord = " ";
			}
			var jumpPage = -1;
			var pageSize = $('#pageSize').val();
			$.get(
				"shop/jumpPage",
				{"bigType":typeId,"keyWord":keyWord,"jump":jumpPage,"pageSize":pageSize},
				function(result){
					location.reload();
				}
			) 
        });  
		//点击上一页
		$("#parentPage").click(function(){ 
			if(keyWord == "" || keyWord==null){
				keyWord = " ";
			}
			var jumpPage = -2;
			var pageSize = $('#pageSize').val();
			$.get(
				"shop/jumpPage",
				{"bigType":typeId,"keyWord":keyWord,"jump":jumpPage,"pageSize":pageSize},
				function(result){
					location.reload();
				}
			) 
        }); 
		//点击首页
		$("#firstPage").click(function(){ 
			if(keyWord == "" || keyWord==null){
				keyWord = " ";
			}
			var jumpPage = -3;
			var pageSize = $('#pageSize').val();
			$.get(
				"shop/jumpPage",
				{"bigType":typeId,"keyWord":keyWord,"jump":jumpPage,"pageSize":pageSize},
				function(result){
					location.reload();
				}
			) 
        }); 
		
		//点击尾页
		$("#lastPage").click(function(){ 
			if(keyWord == "" || keyWord==null){
				keyWord = " ";
			}
			var jumpPage = -4;
			var pageSize = $('#pageSize').val();
			$.get(
				"shop/jumpPage",
				{"bigType":typeId,"keyWord":keyWord,"jump":jumpPage,"pageSize":pageSize},
				function(result){
					location.reload();
				}
			) 
        }); 
		
		//页面大小
		$("#pageSize").change(function(){ 
			if(keyWord == "" || keyWord==null){
				keyWord = " ";
			}
			var jumpPage = -3;
			var pageSize = $('#pageSize').val();
			$.get(
				"shop/jumpPage",
				{"bigType":typeId,"keyWord":keyWord,"jump":jumpPage,"pageSize":pageSize},
				function(result){
					location.reload();
				}
			) 
		});
		
		//跳转
		$("#currentPage").change(function(){ 
			if(keyWord == "" || keyWord==null){
				keyWord = " ";
			}
			var jumpPage = $('#currentPage  option:selected').val()-1;
			var pageSize = $('#pageSize').val();
			$.get(
				"shop/jumpPage",
				{"bigType":typeId,"keyWord":keyWord,"jump":jumpPage,"pageSize":pageSize},
				function(result){
					location.reload();
				}
			) 
		});
		
		
		
		//放大图片
        $(".handler4Left").click(function(){ 
            var _this = $(this).children(".commImg");//将当前的pimg元素作为_this传入函数  
            imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);  
        });  
        
    });  
    function imgShow(outerdiv, innerdiv, bigimg, _this){
        var src = _this.attr("src");//获取当前点击的pimg元素中的src属性  
        $(bigimg).attr("src", src);//设置#bigimg元素的src属性     
            /*获取当前点击图片的真实大小，并显示弹出层及大图*/  
        	var imgObj = $(this).children(".commImg").attr("src", src);
			//imgObj.load(function(){  
            var windowW = $(window).width();//获取当前窗口宽度  
            var windowH = $(window).height();//获取当前窗口高度  
            var realWidth = imgObj.width();//获取图片真实宽度  
            var realHeight = imgObj.height();//获取图片真实高度  
            var imgWidth, imgHeight;  
            imgWidth = 360;//realWidth*0.5;
            imgHeight = 270;//realHeight*0.5;
            $(bigimg).css("width",imgWidth);//以最终的宽度对图片缩放  
            $(bigimg).css("height",imgHeight);//以最终的宽度对图片缩放  
              
            var w = (windowW-imgWidth)/2;//计算图片与窗口左边距  
            var h = (windowH-imgHeight)/2;//计算图片与窗口上边距  
            $(innerdiv).css({"top":h, "left":w});//设置#innerdiv的top和left属性  
            $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg  
        //});  
          
        $(outerdiv).click(function(){//再次点击淡出消失弹出层  
            $(this).fadeOut("fast");  
        });    
    }
});